package ro.pub.cs.client;

import ro.pub.cs.client.settings.SettingsPane;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.DockPanel.DockLayoutConstant;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class HWChecker implements EntryPoint, LeftMenu.SelectionListener {
	private static final int HOMEWORK_PANE_INDEX = 0;
	private static final int CHECKER_PANE_INDEX = 1;
	private static final int GRADES_PANE_INDEX = 2;
	private static final int SETTINGS_PANE_INDEX = 3;
	
	private DockPanel mainPanel = new DockPanel();
	
	private LeftMenu leftMenu = new LeftMenu(this);
	
	private DeckPanel deckPanel = new DeckPanel();
	
	private HomeworkPane homeworkPane = new HomeworkPane();
	private CheckerPane checkerPane = new CheckerPane();
	private GradesPane gradesPane = new GradesPane();
	
	private SettingsPane settingsPane = new SettingsPane();
	
	private VerticalPanel footerPanel = new VerticalPanel();
	
	private void fillDeckPanel() {
		deckPanel.add(homeworkPane);
		deckPanel.add(checkerPane);
		deckPanel.add(gradesPane);
		deckPanel.add(settingsPane);
		deckPanel.setWidth("100%");
		deckPanel.addStyleName("hwc-DeckPanel");
	}
	
	private void fillFooter() {
		HTML copyright = new HTML("Copyright (C) 2008 Stefan Bucur. All rights reserved.");
		
		footerPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
		footerPanel.add(copyright);
		footerPanel.setWidth("100%");
	}
	
	/**
	* This is the entry point method.
	*/
	public void onModuleLoad() {
		
		leftMenu.addHomeworkLink("Homework 1", "Homework1");
		leftMenu.addHomeworkLink("Homework 2", "Homework2");
		leftMenu.addHomeworkLink("Homework 3", "Homework3");
		leftMenu.addHomeworkLink("Homework 4", "Homework4");
		leftMenu.addHomeworkLink("Homework 5", "Homework5");
		leftMenu.setWidth("150px");
		leftMenu.addStyleName("hwc-LeftMenu");
		
		fillDeckPanel();
		
		fillFooter();
		
		
		mainPanel.add(footerPanel, DockPanel.SOUTH);
		mainPanel.add(leftMenu, DockPanel.WEST);
		mainPanel.add(deckPanel, DockPanel.CENTER);
		mainPanel.setWidth("100%");
		mainPanel.setCellWidth(deckPanel, "100%");
		
		RootPanel.get().add(mainPanel);
		
		leftMenu.selectInitial();
	}

	public void onHomeworkSelected(String token) {
		deckPanel.showWidget(HOMEWORK_PANE_INDEX);
	}

	public void onCheckerSelected() {	
		deckPanel.showWidget(CHECKER_PANE_INDEX);
	}

	public void onGradesSelected() {
		deckPanel.showWidget(GRADES_PANE_INDEX);
	}

	public void onSettingsSelected() {
		deckPanel.showWidget(SETTINGS_PANE_INDEX);		
	}	

}
